package main.scala
import org.kiama.util.ParsingREPL

class Prompt extends Parser with ParsingREPL[AST.Exp] {

	override def setup (args : Array[String]) : Boolean = {
		println("Simple Symbolic Calculator started.")
		println("Enter formula, :help for help, :q or ^D to quit.")
		true
	}
	
	/**
	 * Print help message.
	 */
	def help {
	  println ("Some day I may be able to help you, but not right now.")
	}
	
//	lazy val start = Parser.start
	
	/**
	 * Process a command line.
	 */
	override def processline (line : String) {
		line match {
			case ":help" => help
			case ":q" => sys.exit(0)
			case _ => super.processline (line)
		}
	}
	
	/**
	 * Process an expression.
	 */
	def process (e : AST.Exp) {
		println("Hi, I'm Prompt.process, what should I do?")
		print("I read: ")
		println(e)
		// transform the given expression
		val a : AST.Exp = AlgebraicRewriter.start(e)
		println("I understand: " + a)
		// simplify
		val b = SimplifyRewriter.start(a)
		println("I do: " + b)
		// calling the pretty printer
		println("I print: ")
		println(PrettyPrinter.pretty(b))
	}
}